<?php
include "general_include.php";
include "checklogin.php";
$page_name='liked_videos.php';


//$game_id=$_REQUEST['game_id'];

$action_arr=array("list_order","list_search","list_paginate");
if(in_array($action,$action_arr))
{
	$IsProcess = 'Y';
	$smarty->assign('IsProcess',"Y");
	
}
if($IsProcess <> 'Y')
	 include "top.php";


if($game_id=='')
  $GameSql = "SELECT * FROM ".TABLEPREFIX."_game WHERE is_default='Y'";
else
  $GameSql = "SELECT * FROM ".TABLEPREFIX."_game WHERE game_id='$game_id'";  

$gamerow = $UserManagerObjAjax->GetRecords("Row",$GameSql);
$game_id=$gamerow['game_id'];
$game_name=$gamerow['game_name'];

function findvalue($table,$fld_name,$fld_value,$find_value)
	{
		 if($fld_value=='')
				return false;
				
			$SelectTypeSql = "SELECT ".$find_value." FROM ".$table." WHERE $fld_name=".$fld_value;
			$SelectType = mysql_fetch_array(mysql_query($SelectTypeSql));
			return $SelectType[0];
	}	

/* Front Pagination Object Creation Starts */		
 //$PaginationFrontObj=new PaginationClassFrontAjax(15,3,1);
/* Front Pagination Object Creation Ends */
$record_per_page = !empty($record_per_page)?$record_per_page:10000;
$paginationObj = new PaginationClassFrontAjax($record_per_page,3,1,'Next','Previous');


//echo "select video_id FROM ".TABLEPREFIX."_user_like WHERE selected_for='Y' AND selected_by=".$_SESSION['user_id'];
$SelectreplaySql = "SELECT *,date_format(".date_added.",'%M  %d , %Y at %h %i %p') as video_date FROM ".TABLEPREFIX."_video WHERE video_id IN (select video_id FROM ".TABLEPREFIX."_user_like WHERE selected_for='L' AND selected_by=".$_SESSION['user_id'].")";
 $Arr = $UserManagerObjAjax->GetRecords("All",$SelectreplaySql);
 $totRec = count($Arr);
 
 //$PreserveLink="from=$from&from_page=$from_page&".$SearchLink."&".$OrderLink;
 //$preserve_variable_object->PreserveVariableUpdate($PreserveLink);
 	/* pagination starts */
 //$pagination_arr = $PaginationFrontObj->PaginationFrontAjax("PaginationFront",$SelectreplaySql,$page_name."?");	
	/* pagination ends */
 $pagination_arr = $paginationObj->PaginationFrontAjaxALL('PaginationSearch',$SelectreplaySql,$page_name.'?'.$catLink);
 $ReplayArr = $UserManagerObjAjax->GetRecords("All",$pagination_arr[0]);
 $NumReplay = count($ReplayArr);
    for($i=0;$i<$NumReplay;$i++)
	{
		$ReplayArr[$i]['like']='N';
		
		$ReplayArr[$i]['user'] = findvalue(TABLEPREFIX."_user","user_id",$ReplayArr[$i]['user_id'],"name");
		$viewCount = "SELECT count(*) FROM ".TABLEPREFIX."_video_view_count WHERE video_id =".$ReplayArr[$i]['video_id'];
		$viewArr = $UserManagerObjAjax->GetRecords("Row",$viewCount);
		$ReplayArr[$i]['view_count'] = $viewArr[0];
		
		$LikeSql = "SELECT count(*) AS numlike FROM ".TABLEPREFIX."_user_like WHERE selected_for='L' AND video_id=".$ReplayArr[$i]['video_id'] ;
		$LikeArr = $UserManagerObjAjax->GetRecords('Row',$LikeSql);
		
		$UnlikeSql = "SELECT count(*) AS numunlike FROM ".TABLEPREFIX."_user_like WHERE selected_for='D' AND video_id=".$ReplayArr[$i]['video_id'] ;
		$UnlikeArr = $UserManagerObjAjax->GetRecords('Row',$UnlikeSql);
		
		$ReplayArr[$i]['numlike']=$LikeArr['numlike'];
		$ReplayArr[$i]['numunlike']=$UnlikeArr['numunlike'];
		
		
		
	}
	//print_r();



//$gameSql = "SELECT game_id,game_name FROM ".TABLEPREFIX."_game where is_active='Y' ORDER BY game_name";
//$GameArr = $UserManagerObjAjax->HtmlOptionArrayCreate($gameSql);

//$coachSql = "SELECT c.*,cr.* FROM ".TABLEPREFIX."_user c, ".TABLEPREFIX."_user_type_user_relation cr WHERE c.user_id=cr.user_id AND cr.user_type_id=1 AND c.is_active='Y'";
//$coachArr = $UserManagerObjAjax->GetRecords('All',$coachSql);







$smarty->assign('is_coach',$is_coach);
$smarty->assign('is_partner',$is_partner);

$smarty->assign("NumReplay",$NumReplay);
$smarty->assign("totRec",$totRec);
$smarty->assign("LikeArr",$ReplayArr);
$smarty->assign('pagination_arr',$pagination_arr);
$smarty->assign('page_name',$page_name);	
$smarty->register_modifier('in_array', 'in_array');
$smarty->display('liked_videos.tpl');
if($IsProcess <> 'Y')
	 include "footer.php";
?>